'=======================================
' 执行所有测试 case
'=======================================
Private Sub test_ALL_Case()

    ' AddNull 测试
    test_Primitive_AddNull
    ' Add 测试
    test_Primitive_append
    ' Add 异常测试
    test_Primitive_append_error
    ' setVal 测试
    test_Primitive_setVal
    ' setVal 异常测试
    test_Primitive_setVal_error
    ' 0 长度初始化，测试自动扩容
    test_Primitive_auto_expand_INIT_0
    ' 默认长度初始化，测试自动扩容
    test_Primitive_auto_expand_INIT_default
    ' 指定长度初始化，测试自动扩容
    test_Primitive_auto_expand_INIT_5
    ' clear 测试，只清空数据引用
    test_Primitive_clear_byDefault
    ' clear 测试，清空数据后，重新调整内部数组大小
    test_Primitive_clear_by_initCount
    ' remove 测试
    test_Primitive_remove
    ' removeVal 测试
    test_Primitive_removeVal
    ' removeLast 测试
    test_Primitive_removeLast
    ' pollLast: 有数据删除测试 + 空引用删除测试
    test_Primitive_pollLast
    ' getLast 测试
    test_Primitive_getLast
    ' mergeArrRef 测试
    test_Primitive_mergeArrRef
    ' 切片引用 测试
    test_Primitive_slice
    ' clone 测试
    test_Primitive_clone
    ' unsafeRealSize 测试
    test_PrimitiveArrayRef_unsafeRealSize
    ' AddFirst 测试
    test_PrimitiveArrayRef_AddFirst

    ' Insert 测试
    test_PrimitiveArrayRef_Insert
    ' Insert 异常测试 -- 空数组插入，索引 != 0
    test_PrimitiveArrayRef_Insert_error_whenEmpty
    ' Insert 异常测试 -- 数组中存在数据，索引越界 = -1
    test_PrimitiveArrayRef_Insert_error_whenFull_minIndex
    ' Insert 异常测试 -- 数组中存在数据，索引越界 = 索引超过了最大值
    test_PrimitiveArrayRef_Insert_error_whenFull_maxIndex

    ' copyToNewArray 测试
    test_PrimitiveArrayRef_copyToNewArray
End Sub


'=======================================
' PrimitiveArrayRef
'=======================================
' AddNull 测试
Private Sub test_Primitive_AddNull()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef
    arrRef.Add "xx"

    ' 测试不自动扩容
    arrRef.AddNull 5
    Debug.Assert arrRef.Count = 6
    Debug.Assert arrRef.Item(0) = "xx"
    Debug.Assert IsEmpty(arrRef.Item(1))

    arrRef.setVal 1, "yy"
    Debug.Assert arrRef.Item(1) = "yy"

    ' 测试自动扩容
    arrRef.AddNull 20
    Debug.Assert arrRef.Count = 26
    Debug.Assert arrRef.Item(0) = "xx"
    Debug.Assert arrRef.Item(1) = "yy"
    Debug.Assert IsEmpty(arrRef.Item(2))
    Debug.Assert IsEmpty(arrRef.Item(7))
    Debug.Assert IsEmpty(arrRef.Item(25))

    arrRef.setVal 25, "zz"
    Debug.Assert arrRef.Item(25) = "zz"
End Sub

' Add 测试
Private Sub test_Primitive_append()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef

    arrRef.Add "aaa"
    Debug.Assert arrRef.Item(0) = "aaa"
End Sub

' Add 异常测试
Private Sub test_Primitive_append_error()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef

    ' 添加一个对象类型
    Dim c As Collection
    Set c = New Collection
On Error Goto catch
    arrRef.Add c
catch:
    Debug.Assert Err.Number = 10004
End Sub

' setVal 测试
Private Sub test_Primitive_setVal()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef

    arrRef.Add "aaa"
    arrRef.setVal 0, "bbb"
    Debug.Assert arrRef.Item(0) = "bbb"
End Sub

' setVal 异常测试
Private Sub test_Primitive_setVal_error()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef

    arrRef.Add "xx"

    ' 添加一个对象类型
    Dim c As Collection
    Set c = New Collection
On Error Goto catch
    arrRef.setVal 0, c
catch:
    Debug.Assert Err.Number = 10004
End Sub

' 1 长度初始化，测试自动扩容
Private Sub test_Primitive_auto_expand_INIT_0()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(0)

    Dim i As Integer
    For i = 0 To 20
        arrRef.Add "k" & i
    Next

    Debug.Assert arrRef.MaxIndex = 20
    Debug.Assert arrRef.Count = 21
End Sub

' 默认长度初始化，测试自动扩容
Private Sub test_Primitive_auto_expand_INIT_default()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef

    Dim i As Integer
    For i = 0 To 20
        arrRef.Add "k" & i
    Next

    Debug.Assert arrRef.MaxIndex = 20
    Debug.Assert arrRef.Count = 21
End Sub

' 指定长度初始化，测试自动扩容
Private Sub test_Primitive_auto_expand_INIT_5()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    Dim i As Integer
    For i = 0 To 20
        arrRef.Add "k" & i
    Next

    Debug.Assert arrRef.MaxIndex = 20
    Debug.Assert arrRef.Count = 21
End Sub

' clear 测试，只清空数据引用
Private Sub test_Primitive_clear_byDefault()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    Dim i As Integer
    For i = 0 To 20
        arrRef.Add "k" & i
    Next

    arrRef.clear
    Debug.Assert arrRef.Count = 0
    Debug.Assert arrRef.MaxIndex = -1
End Sub

' clear 测试，清空数据后，重新调整内部数组大小
Private Sub test_Primitive_clear_by_initCount()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    Dim i As Integer
    For i = 0 To 20
        arrRef.Add "k" & i
    Next

    arrRef.clear 2
    Debug.Assert arrRef.Count = 0

    For i = 0 To 20
        arrRef.Add "k" & i
    Next

    Debug.Assert arrRef.Count = 21
    Debug.Assert arrRef.MaxIndex = 20
End Sub

' remove 测试
Private Sub test_Primitive_remove()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    arrRef.Add "k0"
    arrRef.Add "k1"
    arrRef.Add "k2"
    arrRef.Add "k3"
    arrRef.Add "k4"

    ' 1. 索引越界测试
    arrRef.remove -1
    Debug.Assert arrRef.Count = 5
    arrRef.remove 5
    Debug.Assert arrRef.Count = 5

    ' 2. 边界删除测试
    arrRef.remove 0
    Debug.Assert arrRef.Count = 4
    Debug.Assert arrRef.Item(0) = "k1"
    Debug.Assert arrRef.Item(1) = "k2"
    Debug.Assert arrRef.Item(2) = "k3"
    Debug.Assert arrRef.Item(3) = "k4"

    arrRef.remove 3
    Debug.Assert arrRef.Count = 3
    Debug.Assert arrRef.Item(0) = "k1"
    Debug.Assert arrRef.Item(1) = "k2"
    Debug.Assert arrRef.Item(2) = "k3"

    ' 3. 删除中间元素
    arrRef.remove 1
    Debug.Assert arrRef.Count = 2
    Debug.Assert arrRef.Item(0) = "k1"
    Debug.Assert arrRef.Item(1) = "k3"
End Sub

' removeVal 测试
Private Sub test_Primitive_removeVal()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    arrRef.Add "kx"
    arrRef.Add "kx"
    arrRef.Add "k0"
    arrRef.Add "kx"
    arrRef.Add "kx"
    arrRef.Add "kx"
    arrRef.Add "k1"
    arrRef.Add "kx"
    arrRef.Add "k2"
    arrRef.Add "kx"

    ' 1. 不存在数据测试
    arrRef.removeVal "--------"
    Debug.Assert arrRef.Count = 10

    ' 2. 只删除第一个相同的值
    arrRef.removeVal "kx"
    Debug.Assert arrRef.Count = 9
    Debug.Assert arrRef.Item(0) = "kx"
    Debug.Assert arrRef.Item(1) = "k0"
    Debug.Assert arrRef.Item(2) = "kx"
    Debug.Assert arrRef.Item(3) = "kx"
    Debug.Assert arrRef.Item(4) = "kx"
    Debug.Assert arrRef.Item(5) = "k1"
    Debug.Assert arrRef.Item(6) = "kx"
    Debug.Assert arrRef.Item(7) = "k2"
    Debug.Assert arrRef.Item(8) = "kx"

    ' 3. 删除所有相同的数据
    arrRef.removeVal "kx", True
    Debug.Assert arrRef.Count = 3
    Debug.Assert arrRef.Item(0) = "k0"
    Debug.Assert arrRef.Item(1) = "k1"
    Debug.Assert arrRef.Item(2) = "k2"
End Sub

' removeLast: 有数据删除测试 + 空引用删除测试
Private Sub test_Primitive_removeLast()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    arrRef.Add "k1"
    arrRef.Add "k2"
    arrRef.Add "k3"
    arrRef.Add "k4"
    arrRef.Add "k5"
    arrRef.Add "k6"

    arrRef.removeLast
    Debug.Assert arrRef.Count = 5
    Debug.Assert arrRef.Item(0) = "k1"
    Debug.Assert arrRef.Item(1) = "k2"
    Debug.Assert arrRef.Item(2) = "k3"
    Debug.Assert arrRef.Item(3) = "k4"
    Debug.Assert arrRef.Item(4) = "k5"

    arrRef.removeLast
    Debug.Assert arrRef.Count = 4
    Debug.Assert arrRef.Item(0) = "k1"
    Debug.Assert arrRef.Item(1) = "k2"
    Debug.Assert arrRef.Item(2) = "k3"
    Debug.Assert arrRef.Item(3) = "k4"

    arrRef.removeLast
    Debug.Assert arrRef.Count = 3
    Debug.Assert arrRef.Item(0) = "k1"
    Debug.Assert arrRef.Item(1) = "k2"
    Debug.Assert arrRef.Item(2) = "k3"

    arrRef.removeLast
    Debug.Assert arrRef.Count = 2
    Debug.Assert arrRef.Item(0) = "k1"
    Debug.Assert arrRef.Item(1) = "k2"

    arrRef.removeLast
    Debug.Assert arrRef.Count = 1
    Debug.Assert arrRef.Item(0) = "k1"

    arrRef.removeLast
    Debug.Assert arrRef.Count = 0

    ' 空删除测试
    arrRef.removeLast
    Debug.Assert arrRef.Count = 0
    arrRef.removeLast
    Debug.Assert arrRef.Count = 0
End Sub

' pollLast: 有数据删除测试 + 空引用删除测试
Private Sub test_Primitive_pollLast()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    arrRef.Add "k1"
    arrRef.Add "k2"
    arrRef.Add "k3"
    arrRef.Add "k4"
    arrRef.Add "k5"
    arrRef.Add "k6"

    Debug.Assert arrRef.pollLast() = "k6"
    Debug.Assert arrRef.Count = 5
    Debug.Assert arrRef.Item(0) = "k1"
    Debug.Assert arrRef.Item(1) = "k2"
    Debug.Assert arrRef.Item(2) = "k3"
    Debug.Assert arrRef.Item(3) = "k4"
    Debug.Assert arrRef.Item(4) = "k5"

    Debug.Assert arrRef.pollLast() = "k5"
    Debug.Assert arrRef.Count = 4
    Debug.Assert arrRef.Item(0) = "k1"
    Debug.Assert arrRef.Item(1) = "k2"
    Debug.Assert arrRef.Item(2) = "k3"
    Debug.Assert arrRef.Item(3) = "k4"

    Debug.Assert arrRef.pollLast() = "k4"
    Debug.Assert arrRef.Count = 3
    Debug.Assert arrRef.Item(0) = "k1"
    Debug.Assert arrRef.Item(1) = "k2"
    Debug.Assert arrRef.Item(2) = "k3"

    Debug.Assert arrRef.pollLast() = "k3"
    Debug.Assert arrRef.Count = 2
    Debug.Assert arrRef.Item(0) = "k1"
    Debug.Assert arrRef.Item(1) = "k2"

    Debug.Assert arrRef.pollLast() = "k2"
    Debug.Assert arrRef.Count = 1
    Debug.Assert arrRef.Item(0) = "k1"

    Debug.Assert arrRef.pollLast() = "k1"
    Debug.Assert arrRef.Count = 0

    ' 空删除测试
    Debug.Assert arrRef.pollLast() = Empty
    Debug.Assert arrRef.Count = 0
    Debug.Assert arrRef.pollLast() = Empty
    Debug.Assert arrRef.Count = 0
End Sub

' getLast 测试
Private Sub test_Primitive_getLast()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    Debug.Assert arrRef.getLast() = Empty

    Dim i As Integer
    For i = 0 To 20
        arrRef.Add "k" & i
    Next

    Debug.Assert arrRef.getLast() = "k20"
End Sub

' mergeArrRef 测试
Private Sub test_Primitive_mergeArrRef()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    Dim others As IPrimitiveArrayRef
    Set others = UtilsArrayRef.createRealPrimitiveArrayRef(2)

    others.Add "o1"
    others.Add "o2"

    arrRef.mergeArrRef others
    Debug.Assert arrRef.Count = 2
    Debug.Assert arrRef.MaxIndex = 1

    arrRef.mergeArrRef others
    Debug.Assert arrRef.Count = 4
    Debug.Assert arrRef.MaxIndex = 3

    arrRef.mergeArrRef others
    Debug.Assert arrRef.Count = 6
    Debug.Assert arrRef.MaxIndex = 5

    Debug.Assert arrRef.Item(0) = "o1"
    Debug.Assert arrRef.Item(1) = "o2"
    Debug.Assert arrRef.Item(2) = "o1"
    Debug.Assert arrRef.Item(3) = "o2"
    Debug.Assert arrRef.Item(4) = "o1"
    Debug.Assert arrRef.Item(5) = "o2"
End Sub

' 切片 测试
Private Sub test_Primitive_slice()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    arrRef.Add "k0"
    arrRef.Add "k1"
    arrRef.Add "k2"
    arrRef.Add "k3"
    arrRef.Add "k4"
    arrRef.Add "k5"

    Dim arr2 As IPrimitiveArrayRef

    ' 测试1:
    ' 如果 `startIdx` >= `endIdx`，将会返回一个空引用
    Set arr2 = arrRef.slice(1, 1)
    Debug.Assert arr2.Count = 0

    Set arr2 = arrRef.slice(2, 1)
    Debug.Assert arr2.Count = 0

    ' 测试2:
    ' 如果 `endIdx` 超过了当前数组引用中元素的数量，则直接截取到数组的结束位置
    Set arr2 = arrRef.slice(3, 100)
    Debug.Assert arr2.Count = 3
    Debug.Assert arr2.Item(0) = "k3"
    Debug.Assert arr2.Item(1) = "k4"
    Debug.Assert arr2.Item(2) = "k5"

    ' 测试3:
    Set arr2 = arrRef.slice(0, 4)
    Debug.Assert arr2.Count = 4
    Debug.Assert arr2.Item(0) = "k0"
    Debug.Assert arr2.Item(1) = "k1"
    Debug.Assert arr2.Item(2) = "k2"
    Debug.Assert arr2.Item(3) = "k3"

    ' 测试4:
    ' 将会返回一个空引用
    Set arr2 = arrRef.slice(-100, -99)
    Debug.Assert arr2.Count = 0

    ' 测试5:
    ' 从 0 开始截取
    Set arr2 = arrRef.slice(0, 4)
    Debug.Assert arr2.Count = 4
    Debug.Assert arr2.Item(0) = "k0"
    Debug.Assert arr2.Item(1) = "k1"
    Debug.Assert arr2.Item(2) = "k2"
    Debug.Assert arr2.Item(3) = "k3"

    ' 测试6:
    ' 完整截取
    Set arr2 = arrRef.slice(0, 6)
    Debug.Assert arr2.Count = 6
    Debug.Assert arr2.Item(0) = "k0"
    Debug.Assert arr2.Item(1) = "k1"
    Debug.Assert arr2.Item(2) = "k2"
    Debug.Assert arr2.Item(3) = "k3"
    Debug.Assert arr2.Item(4) = "k4"
    Debug.Assert arr2.Item(5) = "k5"
End Sub

' clone 测试
Private Sub test_Primitive_clone()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    arrRef.Add "k0"
    arrRef.Add "k1"
    arrRef.Add "k2"
    arrRef.Add "k3"
    arrRef.Add "k4"
    arrRef.Add "k5"

    Dim arr2 As IPrimitiveArrayRef
    Set arr2 = arrRef.clone

    Debug.Assert arr2.Count = 6
    arr2.setVal 1, "xx"

    Debug.Assert arrRef.Item(1) <> arr2.Item(1)
End Sub

' unsafeRealSize 测试
Private Sub test_PrimitiveArrayRef_unsafeRealSize()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef(5)

    arrRef.Add "k0"
    arrRef.Add "k1"
    arrRef.Add "k2"
    arrRef.Add "k3"
    arrRef.Add "k4"
    arrRef.Add "k5"
    arrRef.Add "k6"

    ' 5 --> 5 + 5/2 = 7
    Debug.Assert arrRef.unsafeRealSize = 7
End Sub

' AddFirst 测试
Private Sub test_PrimitiveArrayRef_AddFirst()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef

    arrRef.Add "c1"
    arrRef.AddFirst "c2"
    Debug.Assert arrRef.Item(0) = "c2"
    Debug.Assert arrRef.Item(1) = "c1"

    arrRef.AddFirst Empty
    Debug.Assert arrRef.Item(0) = Empty
    Debug.Assert arrRef.Item(1) = "c2"
    Debug.Assert arrRef.Item(2) = "c1"

    arrRef.AddFirst "c3"
    Debug.Assert arrRef.Item(0) = "c3"
    Debug.Assert arrRef.Item(1) = Empty
    Debug.Assert arrRef.Item(2) = "c2"
    Debug.Assert arrRef.Item(3) = "c1"
End Sub

'--------------------------------------------------------
' Insert 测试
'--------------------------------------------------------
' Insert 测试
Private Sub test_PrimitiveArrayRef_Insert()
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef

    ' ------------------- 1. 基础测试---------------------
    arrRef.Add "c1"
    arrRef.Add "c2"
    arrRef.Add "c3"
    Debug.Assert arrRef.Item(0) = "c1"
    Debug.Assert arrRef.Item(1) = "c2"
    Debug.Assert arrRef.Item(2) = "c3"

    arrRef.Insert 2, "c4"
    Debug.Assert arrRef.Item(0) = "c1"
    Debug.Assert arrRef.Item(1) = "c2"
    Debug.Assert arrRef.Item(2) = "c4"
    Debug.Assert arrRef.Item(3) = "c3"

    ' ------------------- 2. 边界测试---------------------
    arrRef.clear

    arrRef.Insert 0, "c1"
    Debug.Assert arrRef.Item(0) = "c1"
    Debug.Assert arrRef.Count = 1

    arrRef.Add "c2"
    arrRef.Add "c3"
    Debug.Assert arrRef.Item(0) = "c1"
    Debug.Assert arrRef.Item(1) = "c2"
    Debug.Assert arrRef.Item(2) = "c3"
    Debug.Assert arrRef.Count = 3

    arrRef.Insert 3, "c4"
    Debug.Assert arrRef.Item(0) = "c1"
    Debug.Assert arrRef.Item(1) = "c2"
    Debug.Assert arrRef.Item(2) = "c3"
    Debug.Assert arrRef.Item(3) = "c4"
    Debug.Assert arrRef.Count = 4
End Sub

' Insert 异常测试 -- 空数组插入，索引 != 0
Private Sub test_PrimitiveArrayRef_Insert_error_whenEmpty()
On Error Goto catch
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef

    arrRef.Insert -1, "c1"
    Debug.Assert False
    Exit Sub
catch:
    Debug.Assert Err.Description = "IndexOutOfBounds: [index]=-1 out of bounds. count=0]"
End Sub

' Insert 异常测试 -- 数组中存在数据，索引越界 = -1
Private Sub test_PrimitiveArrayRef_Insert_error_whenFull_minIndex()
On Error Goto catch
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef

    arrRef.Add "c1"
    arrRef.Add "c2"
    arrRef.Add "c3"
    Debug.Assert arrRef.Item(0) = "c1"
    Debug.Assert arrRef.Item(1) = "c2"
    Debug.Assert arrRef.Item(2) = "c3"

    arrRef.Insert -1, "c1"
    Debug.Assert False
    Exit Sub
catch:
    Debug.Assert Err.Description = "IndexOutOfBounds: [index]=-1 out of bounds. count=3]"
End Sub

' Insert 异常测试 -- 数组中存在数据，索引越界 = 索引超过了最大值
Private Sub test_PrimitiveArrayRef_Insert_error_whenFull_maxIndex()
On Error Goto catch
    Dim arrRef As IPrimitiveArrayRef
    Set arrRef = UtilsArrayRef.createRealPrimitiveArrayRef

    arrRef.Add "c1"
    arrRef.Add "c2"
    arrRef.Add "c3"
    Debug.Assert arrRef.Item(0) = "c1"
    Debug.Assert arrRef.Item(1) = "c2"
    Debug.Assert arrRef.Item(2) = "c3"

    arrRef.Insert 4, "c1"
    Debug.Assert False
    Exit Sub
catch:
    Debug.Assert Err.Description = "IndexOutOfBounds: [index]=4 out of bounds. count=3]"
End Sub

'--------------------------------------------------------
' copyToNewArray 测试
'--------------------------------------------------------
Private Sub test_PrimitiveArrayRef_copyToNewArray()
    Dim tempRef As IPrimitiveArrayRef
    Dim baseRef As IPrimitiveArrayRef
    Set baseRef = UtilsArrayRef.createRealPrimitiveArrayRef

    ' ------------------- 1. 空拷贝---------------------
    Set tempRef = baseRef.copyToNewArray
    Debug.Assert tempRef.Count = 0

    Set tempRef = baseRef.copyToNewArray(1)
    Debug.Assert tempRef.Count = 0

    Set tempRef = baseRef.copyToNewArray(endIdx := 2)
    Debug.Assert tempRef.Count = 0

    ' ------------------- 2. 边界测试---------------------
    baseRef.Add "c1"
    baseRef.Add "c2"
    baseRef.Add "c3"

    ' 1. 全部拷贝
    Set tempRef = baseRef.copyToNewArray
    Debug.Assert tempRef.Count = 3
    Debug.Assert tempRef.Item(0) = "c1"
    Debug.Assert tempRef.Item(1) = "c2"
    Debug.Assert tempRef.Item(2) = "c3"

    ' 2. 结束索引边界
    Set tempRef = baseRef.copyToNewArray(endIdx := 2)
    Debug.Assert tempRef.Count = 2
    Debug.Assert tempRef.Item(0) = "c1"
    Debug.Assert tempRef.Item(1) = "c2"

    Set tempRef = baseRef.copyToNewArray(endIdx := 3)
    Debug.Assert tempRef.Count = 3
    Debug.Assert tempRef.Item(0) = "c1"
    Debug.Assert tempRef.Item(1) = "c2"
    Debug.Assert tempRef.Item(2) = "c3"

    ' 3. 起始 == 结束
    Set tempRef = baseRef.copyToNewArray(1, 1)
    Debug.Assert tempRef.Count = 0

    ' 4. 起始 > 结束
    Set tempRef = baseRef.copyToNewArray(2, 1)
    Debug.Assert tempRef.Count = 0

    ' 5. 起始 = 结束 - 1
    Set tempRef = baseRef.copyToNewArray(1, 2)
    Debug.Assert tempRef.Count = 1
    Debug.Assert tempRef.Item(0) = "c2"
End Sub
